package com.avcdata

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.SparkContext._

/**
  * https://blog.csdn.net/sdujava2011/article/details/47134465
  *
  * 导入 import org.apache.spark.SparkContext._
  * Scala会将DStream隐式转换成PairDStreamFunctions，
  * 该类中有K/V数据类型相关的函数，例如groupByKey、reduceByKey、join等。
  */

object Main {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("My App")
    val sc = new SparkContext(conf)
    val input = sc.textFile("/Users/hwangchan/Desktop/搭建HA的hdfs.md")
    val words = input.flatMap(line => line.split(" "))
    val counts = words.map(word => (word, 1)).reduceByKey { case (x, y) => x + y }
    counts foreach print
  }
}
